package com.jrx.anytxn.transaction.handler;

import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.customer.dto.customer.CustomerRes;
import com.jrx.anytxn.transaction.bean.CurrentStatementBean;
import com.jrx.anytxn.transaction.bean.LoanSaveBean;
import com.jrx.anytxn.transaction.dto.common.CommonAddReq;
import com.jrx.anytxn.transaction.dto.common.CommonReq;
import com.jrx.anytxn.transaction.dto.common.CommonRes;
import com.jrx.anytxn.transaction.dto.loan.*;
import com.jrx.anytxn.transaction.entity.TlDisbursementLog;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 *  贷款handler接口
 * @author  yf
 * date  2019/9/24 0024
 * @version V1.0
 **/
public interface ILoanHandler {


    /**
     * 贷款确认
     * @author  zhenghaopu
     * date: 2019/9/2 13:34
     * @param loanConfirmReq 贷款确认请求
     * @param customer
     */
    LoanConfirmRes loanConfirmHandler(LoanConfirmReq loanConfirmReq, CustomerRes customer) throws Exception;

    /**
     * 贷款试算
     * @author  fan.yang
     * date: 2019/9/24 0024 下午 14:23
     * @param loanReq 贷款试算请求
     * @return com.jrx.anytxn.common.data.TxnRespResult<com.jrx.anytxn.transaction.dto.loan.LoanConfirmRes>
     */
    LoanConfirmRes loanTrailHandle(LoanReq loanReq) throws Exception;

    /**
     * 查询贷款明细信息
     * @author  fan.yang
     * date: 2019/9/24 0024 下午 14:24
     * @param loanQueryReq 贷款查询请求
     */
    LoanDetailQueryRes loanDetailHandle(LoanQueryReq loanQueryReq) throws TxnException;

    /**
     * 贷款记录查询
     * @author  fan.yang
     * date: 2019/9/24 0024 下午 14:24
     * @param commonReq 贷款记录请求
     */
    LoanRecordQueryRes loanRecordHandle(CommonReq commonReq) throws TxnException;

    /**
     * 放款状态查询
     * @author  fan.yang
     * date: 2019/9/24 0024 下午 14:24
     * @param loanQueryReq 放款状态查询请求
     */
    DisbursementStatusQueryRes disbursementStatusHandle(LoanQueryReq loanQueryReq) throws TxnBizException;

    /**
     * 还款计划查询
     * @author  fan.yang
     * date: 2019/9/24 0024 下午 14:24
     * @param loanPlanQueryReq 还款计划查询
     */
    LoanPlanQueryRes loanPlanHandle(LoanPlanQueryReq loanPlanQueryReq) throws TxnException;

    /**
     * 订单强制入催
     * @author  lbz
     * date: 2020/2/11
     * @param loanCollectionReq 强制入催请求
     */
    LoanCollectionRes loanCollectionHandle(LoanCollectionReq loanCollectionReq)throws TxnBizException;


    /**
     * 账单分期生成订单信息
     * @param loanConfirmReq 请求
     */
    LoanConfirmRes loanConfirmHandlerByLoanStaging(LoanConfirmReq loanConfirmReq) throws Exception;


    /**
     * 当期账单查询
     * @param commonReq
     * @return
     * @throws TxnException
     */
    LoanBillQueryRes loanBillQueryHandle(CommonAddReq commonReq) throws TxnException;

    /**
     * 客户账单查询
     * @param allBillQueryRep
     * @return
     * @throws TxnException
     */
    AllBillQueryRes allBillQueryHandle(AllBillQueryRep allBillQueryRep) throws TxnException;

    /**
     * 待还账单查询
     * @param queryRep
     * @return
     * @throws TxnException
     */
    AllRemainBillQueryRes allRemainBillQueryHandle(CommonAddReq queryRep) throws TxnException;

    /**
     * 账单明细查询
     * @param billDetailQueryRep
     * @return
     * @throws TxnException
     */
    BillDetailQueryRes billDetailQueryRepHandle(BillDetailQueryRep billDetailQueryRep) throws TxnException;

    /**
     * 账单分期订单明细查询
     * @param stagingLoanDetailQueryRep
     * @return
     * @throws TxnException
     */
    StagingLoanDetailQueryRes stagingLoanDetailQueryRepHandle(StagingLoanDetailQueryRep stagingLoanDetailQueryRep) throws TxnException;

    /**
     * 取消订单  不打款的订单才取消
     * @param cancelOrderRep
     * @return
     */
    CancelOrderQueryRes cancelOrderHandle(CancelOrderRep cancelOrderRep) throws Exception;

    /**
     * 取消订单  支付失败后取消
     * @param tlDisbursementLog
     */
    void cancelOrderWithDisbursementLog(TlDisbursementLog tlDisbursementLog) throws TxnBizException;

    /**
     * 修改放款信息
     * @param modifyLoanInfoReq
     * @return
     */
    ModifyLoanInfoRes modifyLoanInfoHandle(ModifyLoanInfoReq modifyLoanInfoReq) throws Exception;

    /**
     * 校验封锁码
     * @param blockCode
     * @param tenantId
     * @throws TxnException
     */
    void validateBlockCode(String blockCode, String tenantId) throws TxnException;

    /**
     * 同步API放款失败信息
     *
     * @param syncLoanFailInfoReq
     * @return CommonRes
     */
    CommonRes syncLoanFailInfoHandle(SyncLoanFailInfoReq syncLoanFailInfoReq) throws TxnBizException;

    /**
     * 获取当期账单日还款日
     * @param productId
     * @param statementDd
     * @param paymentDd
     * @param bussinessDate
     * @return
     */
    CurrentStatementBean getCurrentStatement(String productId, int statementDd, int paymentDd, Date bussinessDate);

    /**
     * 获取对应账单日的还款日
     * @param statementDate
     * @param paymentDd
     * @return
     */
    Date getCurrentPaymentDate(Date statementDate,int paymentDd);

    /**
     * 账单详情查询
     * @param billDetailsInquiryReq
     * @return
     */
    BillDetailsInquiryRes billDetailsInquir(BillDetailsInquiryReq billDetailsInquiryReq) throws Exception;

    /**
     * 借款记录查询
     * @param req
     * @return
     */
    LoanListQueryRes loanListQuery(LoanListQueryReq req) throws TxnBizException;

    /**
     * 通知api-server放款状态更新
     * @param log
     * @param completeDate
     * @param contractNumber
     * @throws TxnBizException
     */
    void disbursementStatus(TlDisbursementLog log, Date completeDate, String contractNumber) throws TxnBizException;


    /**
     * PCP放款结果回调处理
     * @param req
     * @return
     */
    LoanCallBackRes loanCallBackHandle(LoanCallBackRep req) throws Exception;

    /**
     * 获取对应账单日的还款日
     * @param statementDate
     * @param paymentDd
     * @param bussinessDate
     * @param products
     * @return
     */
    Date getCurrentPaymentDate(Date statementDate,int paymentDd, Date bussinessDate, List<String> products);

    /**
     * 账单待还明细
     * @param billDetailsInquiryReq
     * @return
     */
    BillDetailsInquiryRes billWaitingDetails(BillDetailsInquiryReq billDetailsInquiryReq) throws Exception;

    /**
     * 行内交易状态转换放款最终状态
     * @param operStatus 放款回调 行内交易状态  00-待处理，01-已记账，02-已抹账，03-退汇完成
     * @param updateLog
     * @return
     */
    void getDisSumStatus(String operStatus, TlDisbursementLog updateLog);

    /**
     * 贷款罚息逾期天数查询
     * @param loanDlayIntcDelqDaysQueryReq
     * @return
     */
    LoanDlayIntcDelqDaysQueryRes loanDlayIntcDelqDaysHandle(LoanDlayIntcDelqDaysQueryReq loanDlayIntcDelqDaysQueryReq);

    /**
     * 处理放款结果
     * @param log
     * @param loanSaveBean
     * @param businessDate
     * @param updateLog
     * @param result
     * @return
     * @throws Exception
     */
    void dealLoanResult(TlDisbursementLog log, LoanSaveBean loanSaveBean, Date businessDate, TlDisbursementLog updateLog, String result) throws Exception;

    /**
     * 兴安借产品放款结果查询处理
     * @param updateLog
     * @param productId
     * @param queryMaxCounts
     * @return
     */
    TlDisbursementLog queryLoanStatusByXaj(TlDisbursementLog updateLog, String productId, Integer queryMaxCounts);

    /**
     *  保存或者修改放款信息
     * @param items
     */
    void saveOrUpdateLoan(List items);

    /**
     * 查询总欠款
     * @param channel
     * @param customerId
     * @param tenantId
     * @param productId
     * @return
     */
    BigDecimal getLoanTotalAmount(String channel, String customerId, String tenantId, String productId) throws TxnBizException;
}
